package org.guegan.util.dircompare.util;

public class ByteToHexString {
	public static String toHex(byte [] array) {
		StringBuilder ret = new StringBuilder(array.length * 2);
		for (int i = 0; i < array.length; i++) {
			String val = Integer.toHexString(array[i]);
			int idx = val.length();
			if (idx > 2) {
				idx -= 2;
				ret.append(val.substring(idx, idx + 2));
			}
			else {
				while (idx < 2) {
					ret.append('0');
					idx++;
				}
				ret.append(val);
			}
		}
		return ret.toString();
	}
}
